#include <vector>
using namespace std;


class Solution 
{
public:
      
    int massage(vector<int>& nums) 
    {
        int num = nums.size();
        if(num == 0) return 0;

        vector<int> g(num), f(num);

        f[0] = nums[0], g[0] = 0;
        for(int i=1; i<num; i++)
        {
            f[i] = g[i-1] + nums[i];
            g[i] = max(f[i-1], g[i-1]);
        }

        return max(f[num-1], g[num-1]);
    }

    int rob(vector<int>& nums) 
    {
        int n = nums.size();
        if(n == 1) return nums[0];
        if(n == 2) return max(nums[0],nums[1]);
        //偷 
        vector<int> v1(nums.begin() + 2, nums.end() - 1);
        //不偷
        vector<int> v2(nums.begin() + 1, nums.end());

        int x = massage(v1) + nums[0];
        int y = massage(v2);
        
        return max(x, y);
    }   
};